﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing;

namespace Basic.Core.Application.Services;

[ApiController]
[Route("[controller]")]
public abstract class ApiApplicationService : IApplicationService
{
    private ControllerContext _controllerContext;

    [ControllerContext]
    public ControllerContext ControllerContext
    {
        get
        {
            if (this._controllerContext == null)
                this._controllerContext = new ControllerContext();
            return this._controllerContext;
        }
        set => this._controllerContext = value != null ? value : throw new ArgumentNullException(nameof(value));
    }

    public HttpRequest Request => this.ControllerContext.HttpContext?.Request;

    public HttpResponse Response => this.ControllerContext.HttpContext?.Response;

    public RouteData RouteData => this.ControllerContext.RouteData;

    public ModelStateDictionary ModelState => this.ControllerContext.ModelState;

}